package com;

import java.io.*;

public class FileTest {


    public static void main(String[] args) throws IOException {
        //字符流
        File file = new File("C:\\Users\\admin\\IdeaProjects\\newAli\\order-sentinel\\src\\main\\java\\com\\hello.txt");
        System.out.println(file.getAbsolutePath());//文件路径
        System.out.println(file.isFile());//当且仅当此抽象路径名表示的文件存在并且是 普通文件时才为true ；否则false
        System.out.println(file.length());//字符长度
        System.out.println(file.exists());//当且仅当此抽象路径名表示的文件或目录存在时才为true ；否则false
        FileReader fileReader = new FileReader(file);
        int read = fileReader.read();//读取一个字符,对应的ascall表的值，如果已到达流的末尾，则为 -1
        System.out.println((char) read);
        StringBuilder stringBuilder = new StringBuilder();
        while (read != -1) {
            stringBuilder.append((char) read);
            read = fileReader.read();
        }
        System.out.println(stringBuilder);
        char[] chars = new char[100];
        int read1 = fileReader.read();
        int index = 0;
        int i = 0;
        while ((i = read1) != -1) {
            chars[index] = (char) i;
            index++;
        }
        System.out.println(chars.toString());
        fileReader.close();


        FileWriter fileWriter = new FileWriter(file, true);//开启追加写
        for (int j = 0; j < 10000; j++) {
            fileWriter.write("\n小明||12||南昌");
        }
        fileWriter.close();
    }
}
